Skip to content

Fix: correctly pipe keyword arguments to plot_dendrogram#65

Merged
mstimberg merged 6 commits intobrian-team:masterfrom
Utkarsha2811:fix-dendrogram-kwargs
Mar 27, 2026
Merged

Fix: correctly pipe keyword arguments to plot_dendrogram#65
mstimberg merged 6 commits intobrian-team:masterfrom
Utkarsha2811:fix-dendrogram-kwargs

Conversation

@Utkarsha2811
Copy link
Copy Markdown
Contributor

@Utkarsha2811 Utkarsha2811 commented Mar 14, 2026

Fix: Pass styling keyword arguments through plot_dendrogram
Problem
When calling plot_dendrogram (or brian_plot on a morphology), any styling arguments like color='red' or alpha=0.5 were silently ignored. There was no way to customize the appearance of the dendrogram tree.
Solution
Added **kwds support to plot_dendrogram so that styling arguments are now correctly forwarded to the three underlying matplotlib calls: plot, vlines, and hlines. This means users can now do:
plot_dendrogram(morpho, color='red', alpha=0.7, linewidth=2)
brian_plot(morpho, color='blue')

Changes
brian2tools/plotting/morphology.py — plot_dendrogram now accepts **kwds and passes them to all three matplotlib drawing calls. Updated the docstring to clearly state that kwargs go to plot, vlines, and hlines, and that only arguments compatible with all three (e.g. color, alpha, linewidth) should be used.
brian2tools/tests/test_plotting.py — Added test cases verifying that plot_dendrogram works correctly with color, alpha, and linewidth kwargs, and that these kwargs also flow through correctly when using brian_plot.
docs_sphinx/user/plotting.rst — Removed the outdated note saying plot_dendrogram "does not allow any customization at the moment". Replaced it with an accurate description of the new kwargs support, including a usage example.

@mstimberg
Copy link
Copy Markdown
Member

Hi @Utkarsha2811, thanks for the PR, passing on the keywords makes indeed sense. Could you please include this feature in the tests? Also, I think the documentation needs to state that the arguments are given to plot, hlines, and vlines, so only arguments that work for all of them are allowed (the most relevant are probably very generic anyway, things like color, alpha and maybe `linewidth).

@Utkarsha2811
Copy link
Copy Markdown
Contributor Author

Hey @mstimberg, sure will check, I'll push the changes and update the doc.

@Utkarsha2811 Utkarsha2811 marked this pull request as draft March 19, 2026 17:09
@Utkarsha2811 Utkarsha2811 force-pushed the fix-dendrogram-kwargs branch from be5a2a2 to 8f8b536 Compare March 21, 2026 13:23
@Utkarsha2811 Utkarsha2811 marked this pull request as ready for review March 21, 2026 17:42
@Utkarsha2811
Copy link
Copy Markdown
Contributor Author

Hey @mstimberg,

I’ve updated the PR based on the review comments and also revised the PR description to reflect the changes more clearly. Please take a look when you get a chance and let me know what you think.

though the build failure is being fixed in
#67

Once it is merged, I'll rebase this PR (then build should pass).

Copy link
Copy Markdown
Member

@mstimberg mstimberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update, two more small comments below.

Comment thread brian2tools/plotting/morphology.py Outdated
# Plot the dendogram with lengths of the vertical lines representing the
# total distance to the root
plt.plot(x_values[0], length_metric[0], 'ko', clip_on=False)
plt.plot(x_values[0], length_metric[0], marker='o', clip_on=False, **kwds)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will rarely occur, but it would be cleaner if we dealt with the situation that the user provides clip_on or lw (see below) as keyword arguments themselves, which currently breaks with a "keyword argument repeated" error.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, Addressed

Comment thread docs_sphinx/user/plotting.rst Outdated
The `~brian2tools.plotting.morphology.plot_dendrogram` function does the same thing, but in contrast to the other
plot functions it does not allow any customization at the moment, so there is no benefit over using
`~brian2tools.plotting.base.brian_plot`.
The `~brian2tools.plotting.morphology.plot_dendrogram` function does the same thing, but also accepts additional
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous text is still correct: plot_dendrogram does not add any functionality over brian_plot, since you can also give the keyword arguments to brian_plot. It would still be nice to give an example for the keyword arguments, but 1) stating that this is possible both with brian_plot and plot_dendrogram, and 2) including an example image in the documentation.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, updated the doc

@mstimberg
Copy link
Copy Markdown
Member

Thanks for the update @Utkarsha2811. The file plot_dendrogram_custom.svg seems to be missing from your commit, though.

@Utkarsha2811
Copy link
Copy Markdown
Contributor Author

Thanks for the update @Utkarsha2811. The file plot_dendrogram_custom.svg seems to be missing from your commit, though.

Thanks for reviewing @mstimberg, I missed generating plot image, Added!

@Utkarsha2811 Utkarsha2811 requested a review from mstimberg March 27, 2026 07:31
Copy link
Copy Markdown
Member

@mstimberg mstimberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks

@mstimberg mstimberg merged commit a9a59d3 into brian-team:master Mar 27, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants